<?php
/**
* @file appad.php
* @date: 2015-8-20 下午2:18:39
* @author: xiweijie
*/
namespace haibao\app\data;

class Appad extends \haibao\app\data\BaseMysql{
	
	public function __construct(){
		parent::__construct('\haibao\app\model\data\Area');
		$this->setConfig( \haibao\classlibrary\app\Config::CLASSLIBRARY_CONFIG_MYSQL_NEW_BI_UTF8 );
	}
	
	public function getTodayExistAdInfo($zoneId){
		$cache = new \haibao\app\cache\Appad();
		$result = $cache->getZoneInfo($zoneId);
		if(empty($result)){
			$result = $this->getZoneAdInfo($zoneId);
		}
		return $result;
	}
	
	public function getZoneAdInfo($zoneId){
		$time = date('Y-m-d');
		$key = $zoneId;
		$num = 0;
		$result = array('num'=>$num);
		if($zoneId == 1014){
			$zoneId = '1014,1015,1016,1017,1018';
		}
		$sql = "SELECT count(*) as num FROM `sheets` WHERE order_id<>'' and time='".$time."' and `status`=2 and product_id in (".$zoneId.")";
		$data = $this->query($sql);
		while ($data->fetch_assoc()){
			$result['num'] = $data->getData('num');
			$num = $result['num'];
		}
		$cache = new \haibao\app\cache\Appad();
		$cache->setZoneInfo($key, array('num'=>$num),300);
		return $result;
	}
}